package net.lgpage.view;

import com.matriq.cloudmanager.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

@SuppressLint({ "NewApi" })
public class ViewpagerIndicator extends LinearLayout {
	BaseAdapter mAdapter;
	ViewPager mViewPager;

	public ViewpagerIndicator(Context paramContext) {
		super(paramContext);
	}

	public ViewpagerIndicator(Context paramContext, AttributeSet paramAttributeSet) {
		super(paramContext, paramAttributeSet);
	}

	public ViewpagerIndicator(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
		super(paramContext, paramAttributeSet, paramInt);
	}

	public void setAdapter(BaseAdapter paramBaseAdapter) {
		this.mAdapter = paramBaseAdapter;
		removeAllViews();
		for (int i = 0;; i++) {
			if (i >= this.mAdapter.getCount())
				return;
			addView(this.mAdapter.getView(i, null, this));
		}
	}

	public void setViewPager(ViewPager paramViewPager) {
		this.mViewPager = paramViewPager;
		setAdapter(new PageIndexAdapter());
		paramViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			public void onPageScrollStateChanged(int paramInt) {
			}

			public void onPageScrolled(int paramInt1, float paramFloat, int paramInt2) {
			}

			public void onPageSelected(int paramInt) {
				for (int i = 0;i<getChildCount(); i++) {
					((ImageView) ViewpagerIndicator.this.getChildAt(i)).setBackgroundResource(R.drawable.offffff_l1);
				}
				if(paramInt<getChildCount())
				((ImageView) ViewpagerIndicator.this.getChildAt(paramInt))
				.setBackgroundResource(R.drawable.offffff);
			}
		});
	}

	private class PageIndexAdapter extends BaseAdapter {
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(28, 28);

		public PageIndexAdapter() {
			this.lp.setMargins(13, 0, 13, 0);
		}

		public int getCount() {
			if ((ViewpagerIndicator.this.mViewPager == null)
					|| (ViewpagerIndicator.this.mViewPager.getAdapter() == null))
				return 0;
			return ViewpagerIndicator.this.mViewPager.getAdapter().getCount();
		}

		public Object getItem(int paramInt) {
			return null;
		}

		public long getItemId(int paramInt) {
			return 0L;
		}

		public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
			ImageView localImageView = new ImageView(ViewpagerIndicator.this.getContext());
			localImageView.setLayoutParams(this.lp);
			if (paramInt == ViewpagerIndicator.this.mViewPager.getCurrentItem())
				localImageView.setBackgroundResource(R.drawable.offffff);
			else {
				localImageView.setBackgroundResource(R.drawable.offffff_l1);
			}
			return localImageView;
		}
	}
}